﻿using System;

namespace studentSubsidy.Utils
{
    public class GenerateID
    {
        public string BuildRandomStr(int length)
        {
            Random rand = new Random();
            int num = rand.Next();
            string str = num.ToString();
            if (str.Length > length)
            {
                str = str.Substring(0, length);
            }
            else if (str.Length < length)
            {
                int n = length - str.Length;
                while (n > 0)
                {
                    str.Insert(0, "0");
                    n--;
                }
            }
            return str;
        }

        public static int GenerateId()
        {
            byte[] buffer = Guid.NewGuid().ToByteArray();
            return BitConverter.ToInt32(buffer, 0);
        }
        
        public static int GenForInt() //自动生成int型的随机数据 
        {
            Random Rdm = new Random();
            int iRdm = Rdm.Next(0, 10000);
            return iRdm;
        }

        public static long GenLongByTime()
        {
            DateTime now = DateTime.Now;
            long t = now.ToFileTime();
            return t;
        }
    }
}